package main

import (
	"fmt"
	"io"
	"net/http"
	"strings"
)

func main() {
	//	r, e := http.Get("http://127.0.0.1:8021/myGo?GetPara1=1&GetPara2=2")
	// 法1
	r, e := http.Post(
		"http://127.0.0.1:8021/myGo?GetPara1=1&GetPara2=2",
		"application/x-www-form-urlencoded",
		strings.NewReader("PostPara1=post1"))

	// 法2
	/*
		r, e := http.PostForm("http://127.0.0.1:8021/myGo?GetPara1=1&GetPara2=2",
			url.Values{"PostPara1": {"post1"}, "PostPara2": {"post2"}})
	*/
	if e != nil {
		fmt.Println("err:", e)
	}
	defer r.Body.Close()

	bytes := make([]byte, 1024)

	fmt.Println("网页内容为：")
	for {
		n, err := r.Body.Read(bytes)
		//	log.Println("n:", n)
		if n == 0 {
			fmt.Println()
			fmt.Println("====读取结束==== ")
			break
		} else if err != nil && err != io.EOF {
			fmt.Println("错误err:", err)
		}

		fmt.Print(string(bytes[:n]))
	}

}
